<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="80px">
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="项目名称:" prop="xmName">
            <el-input
              v-model="queryParams.xmName"
              placeholder="请输入项目名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="项目编号:" prop="xmBh">
            <el-input
              v-model="queryParams.xmBh"
              placeholder="请输入项目编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="申报单位:" prop="sbDw">
            <el-input
              v-model="queryParams.sbDw"
              placeholder="请输入申报单位"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="项目年度:" prop="nd">
            <el-select v-model="queryParams.nd" placeholder="请选择项目年度" clearable size="small">
              <el-option
                v-for="dict in dict.type.year"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="课题归属:" prop="ktGs">
            <el-select v-model="queryParams.ktGs" placeholder="请选择课题归属" clearable size="small">
              <el-option
                v-for="dict in dict.type.kylx_ktgs"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              height="300" class="fixedTableTwo" v-loading="loading" :data="fyGzList"
              @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column show-overflow-tooltip label="年度" align="center" prop="nd"/>
      <el-table-column show-overflow-tooltip label="项目名称" align="center" prop="xmName">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary">{{ scope.row.xmName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="项目编号" align="center" prop="xmBh"/>
      <el-table-column show-overflow-tooltip label="申报单位" align="center" prop="sbDw"/>
      <el-table-column show-overflow-tooltip label="项目总额" align="center" prop="xmZe">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="xmZeButtonClick(scope.row)"
          >
            <el-link type="primary">{{ scope.row.xmZe }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="申请资助" align="center" prop="sqZz"/>
      <el-table-column show-overflow-tooltip label="课题归属" align="center" prop="ktGs"/>
      <el-table-column show-overflow-tooltip label="计划开始时间" align="center" prop="jhKsSj"/>
      <el-table-column show-overflow-tooltip label="计划结束时间" align="center" prop="jhJsSj"/>
      <el-table-column show-overflow-tooltip label="申报日期" align="center" prop="sbRq"/>
      <el-table-column show-overflow-tooltip label="载账金额" align="center" prop="zzJe"/>
      <el-table-column label="月报费用查看" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="vxe-icon-paste"
            @click="handleYbFy(scope.row)"
          >月报费用查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 月报费用 -->
    <YbFy ref="ybFy"/>

    <!-- 查询项目申报(主表 + 子表) 弹窗 -->
    <xmxq ref="xmxq"/>

    <!-- 查看项目预算 弹窗 -->
    <XmZe ref="xmze"/>
  </div>
</template>

<script>
import {selectFygzList} from "@/api/jjkc/fygz";
import YbFy from "@/views/fztz/lsck/ybfy/YbFy.vue";
import Xmxq from "@/views/xmgl/lxgl/xmsb/components/xmxq.vue";
import XmZe from "@/views/xmgl/lxgl/xmsb/components/xmZe.vue";

export default {
  name: "FyGz",
  components: {XmZe, Xmxq, YbFy},
  dicts: ['kylx_ktgs', 'year'],
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 非多个禁用
      multiple: true,
      // 非单个禁用
      single: true,
      // 选中数组
      ids: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xmName: null,
        xmBh: null,
        sbDw: null,
        nd: null,

      },
      // 遮罩层
      loading: true,
      //费用跟踪列表数据
      fyGzList: [],

    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 查询项目总额信息(打开项目总额弹窗)
    xmZeButtonClick(row) {
      this.$refs.xmze.handleOpen(row);
    },
    // 项目申报详情
    handleButtonClick(row) {
      this.$refs.xmxq.handleOpen(row);
    },
    //月报费用
    handleYbFy(row) {
      this.$refs.ybFy.handleOpen(row)
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    getList() {
      this.loading = true;
      selectFygzList(this.queryParams).then(res => {
        this.fyGzList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    //点击行 获取行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.xmsbId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jjkc/fygz/export', {
        ...this.queryParams
      }, `费用跟踪_${new Date().getTime()}.xlsx`)
    },

  }
}
</script>

<style scoped>

</style>
